---
title: Configuration.encodeHTTPResponse()
api: Configuration.encodeHTTPResponse
---

## Description

<Summary/>

<FilterDiagram
  name="encodeHTTPResponse"
  input="Message"
  output="Data"
/>

The encoder expects an input [Message](/reference/api/Message) to have:

* _head_
  - _protocol_ - Can be _"HTTP/1.0"_ or _"HTTP/1.1"_ (Defaults to _"HTTP/1.1"_)
  - _status_ - Response status code (Defaults to _200_)
  - _statusText_ - Response reason phrase (Defaults to _"OK"_)
  - _headers_ - Header fields
* _body_ - Message body

If any fields are missing in [Message.head](/reference/api/Message/head), their default values will be taken.

This filter only supports HTTP/1.x. For compatibility with HTTP/2, check out [demuxHTTP()](/reference/api/Configuration/demuxHTTP).

### Response to HEAD requests

When encoding a response to a HEAD request, you need to tell the filter that the response is supposed to have no body following the header. You do so by the _bodiless_ option in the _options_ parameter. It can be a boolean value or a function that returns a boolean value.

### Chunked transfer

When encoding a response, the [Content-Length](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Length) header needs to come before the body, so **encodeHTTPRequest** has to buffer the entire body until it sees a _MessageEnd_ event, only by then can the filter output a value for _Content-Length_ header, followed by the previously buffered body.

The buffering is limited to 4KB by default. When the buffered data is over 4KB, the encoder will opt for [chunked encoding](https://developer.mozilla.org/docs/Web/HTTP/Headers/Transfer-Encoding#chunked_encoding), where a _Content-Length_ header is no longer needed. You can change this limit by the option _bufferSize_ in the _options_ parameter.

## Syntax

``` js
pipy()
  .pipeline()
  .encodeHTTPResponse()

pipy()
  .pipeline()
  .encodeHTTPResponse({
    final,
    bodiless,
    bufferSize,
  })
```

## Parameters

<Parameters/>

## See Also

* [Configuration](/reference/api/Configuration)
* [encodeHTTPRequest()](/reference/api/Configuration/encodeHTTPRequest)
* [decodeHTTPRequest()](/reference/api/Configuration/decodeHTTPRequest)
* [decodeHTTPResponse()](/reference/api/Configuration/decodeHTTPResponse)
* [demuxHTTP()](/reference/api/Configuration/demuxHTTP)
